﻿#pragma once

#include <drogon/HttpController.h>
#include "OCServer/DocGenerate.h"
using namespace drogon;
using namespace OCPP;

class MyDoc
{
public:
	static void doc(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback,String queryapi)
	{
		String docClass = "CAPService";
		if (queryapi == "")
		{
			auto resp = drogon::HttpResponse::newRedirectionResponse("/swagger/index.html?s=" + docClass);
			callback(resp);
		}
		else if (queryapi == "api")
		{
			static String body;
			if (body.empty())
			{
				OpenApiDoc doc;
				doc.setBaseUrl("/" + docClass);
				doc.addMethod().setPath("/getTimeList").setDescription("获取时间列表")
					.addParameter("startTime", "开始时间", "query", "string", "2024-07-24 00:00:00")
					.addParameter("endTime", "结束时间", "query", "string", "2024-07-24 23:59:59");

				doc.addMethod().setPath("/get").setDescription("组合反射率cref")
					.addParameter("time", "时间", "query", "string", "2024-07-24 00:00:00")
					.addParameter("product", "产品", "query", "string", "cref");

				doc.addMethod().setPath("/getCAP3D").setDescription("三维组网分层数据")
					.addParameter("time", "时间", "query", "string", "2024-07-24 00:00:00")
					.addParameter("z", "固定", "query", "int", "3")
					.addParameter("startX", "起始列", "query", "int", "5")
					.addParameter("startY", "起始行", "query", "int", "3")
					.addParameter("endX", "结束列", "query", "int", "6")
					.addParameter("endY", "结束行", "query", "int", "4");

				body = doc.toString();
			}
			HttpResponsePtr resp = HttpResponse::newHttpResponse();
			resp->setBody(body);
			resp->setContentTypeCode(drogon::ContentType::CT_APPLICATION_JSON);
			callback(resp);
		}
		else
		{
			auto resp = HttpResponse::newNotFoundResponse();
			callback(resp);
		}
	}
};

